// const promise = new Promise((resolve, reject) => {
//     undecalaredVariable++;
// });
//
// promise.then(()=> {console.log("Happy path, won't be called")})
//     .catch(error=>{console.log('here is a error')});

function getJson(url) {
    return new Promise((resolve, reject) => {
        const request = new XMLHttpRequest();
        request.open("GET", url);
        request.onload = function () {
            try {
                if(this.status === 200) {
                    resolve(JSON.parse(this.response));
                }else {
                    reject(this.status + " " + this.statusText);
                }
            }catch (e) {
                reject(e.message);
            }
        };
        request.onerror = function () {
            reject(this.status + " " + this.statusText);
        };
        request.send();
    })
}